package com.wkbb.common.dto.basic;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wkbb.common.enums.RelationTypeEnum;
import com.wkbb.common.handler.JsonUtil;
import com.wkbb.common.utils.RSAUtil;
import com.wkbb.common.utils.StringUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author dengjingyuan
 * @date 2019-07-04 15:58
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class StudentInfoDto implements Serializable {

    @ApiModelProperty(value = "入学年份")
    private Integer enrollmentYear;
    @ApiModelProperty(value = "累计上课数量")
    private int courseTimeNum;
    @ApiModelProperty(value = "报班数量")
    private int signUpNum;
    @ApiModelProperty(value = "请假次数")
    private int leaveNum;
    @ApiModelProperty(value = "缺勤次数")
    private int absenceNum;
    @ApiModelProperty(value = "是否已报班")
    private Boolean signUp;
    @ApiModelProperty(value = "是否已绑定小程序")
    private Boolean isBindApplet;
    @ApiModelProperty(value = "是否自动创建")
    private Boolean autoCreate;
    public Boolean getSignUp() {
        return signUpNum > 0;
    }

    @ApiModelProperty(value = "累计跳绳次数")
    private Integer totalTrainCount;
    @ApiModelProperty(value = "累计跳绳耗时（秒）")
    private Integer totalTrainTime;
    @ApiModelProperty(value = "累计打卡(天)")
    private Integer dayNum;

    @ApiModelProperty(value = "用户类型 1学生 2爸爸 3妈妈 4其他")
    private Integer userType;
    @ApiModelProperty(value = "是否已经实名认证")
    private Boolean hasFaceRecognition;
    @ApiModelProperty(value = "是否已经上传人脸")
    private String idCard;
    @ApiModelProperty(value = "人脸照片")
    private String faceImgUrl;

    @ApiModelProperty(value = "学校编号")
    private Long schoolId;
    @ApiModelProperty(value = "编号")
    private Long id;

    @ApiModelProperty(value = "用户ID")
    private Long userId;

    @ApiModelProperty(value = "组织ID")
    private Long orgId;

    @ApiModelProperty(value = "修改前所在学校组织ID")
    private Long oldOrgId;

    @ApiModelProperty(value = "年级")
    private Long gradeId;

    @ApiModelProperty(value = "年级名称")
    private String gradeName;

    @ApiModelProperty(value = "班级ID")
    private Long classId;

    @ApiModelProperty(value = "班级名称")
    private String className;

    @ApiModelProperty(value = "姓名")
    private String name;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "头像")
    private String headImgUrl;

    @ApiModelProperty(value = "性别")
    private String sex;

    @ApiModelProperty(value = "出生日期")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthDate;

    @ApiModelProperty(value = "手机号")
    private String mobile;

    @ApiModelProperty(value = "家长手机号")
    private String familyMobile;

    @ApiModelProperty(value = "省份CODE")
    private String provinceCode;

    @ApiModelProperty(value = "省份")
    private String province;

    @ApiModelProperty(value = "城市CODE")
    private String cityCode;

    @ApiModelProperty(value = "城市")
    private String city;

    @ApiModelProperty(value = "区镇CODE")
    private String areaCode;

    @ApiModelProperty(value = "区镇")
    private String area;

    @ApiModelProperty(value = "地址")
    private String addr;

    @ApiModelProperty(value = "卡号")
    private Object cardNo;

    @ApiModelProperty(value = "用户编号")
    private String userCode;

    @ApiModelProperty(value = "学号")
    private String studentNo;

    /**
     * 入园时间
     */
    @ApiModelProperty(value = "入园时间")
    @JSONField(format = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date enterDate;

    /**
     * 民族
     */
    @ApiModelProperty(value = "民族")
    private String nationality;

    /**
     * 姓名发音
     */
    private String speakName;

    @ApiModelProperty(value = "学校名称")
    private String orgName;

    /**
     * 以下字段只有个人中心和家长管理用到
     */
    private Integer relationType;

    @ApiModelProperty(value = "称呼")
    private String relationTypeName;

    @ApiModelProperty(value = "组织架构Id")
    private Long structureId;

    @ApiModelProperty(value = "组织架构用户Id")
    private Long structureUserId;

    @ApiModelProperty(value = "智慧校园用户ID")
    private String smartUserId;

    @ApiModelProperty(value = "智慧校园用户微信ID")
    private String smartWxUserId;

    @ApiModelProperty(value = "是否已关注智慧校园公众号1是0否")
    private Boolean isSmartSubscribe;

    public String getRelationTypeName() {
        if(StringUtil.isNotEmpty(relationTypeName)){
            return relationTypeName;
        }else {
            if (relationType == null) {
                return null;
            }
            return RelationTypeEnum.getDesc(this.relationType);
        }
    }

    @ApiModelProperty(value = "原班级ID")
    private Long oriClassId;

    @ApiModelProperty(value = "是否已经上传人脸")
    private Boolean hasUploadFace = false;

    @ApiModelProperty(value = "账号ID")
    private Long accountId;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "人脸录入时间")
    private String createTime;

    public int stuIndex(){
        if(studentNo != null && !"".equals(studentNo)){
            StringBuilder sb = new StringBuilder();
            for(int i=0;i<studentNo.length();i++){
                if(studentNo.charAt(i)>=48 && studentNo.charAt(i)<=57){
                    sb.append(studentNo.charAt(i));
                }
            }
            if (!"".equals(sb.toString())) return Integer.parseInt(sb.toString());
        }
        return 0;
    }

    public static void main(String[] args) {
        StudentInfoDto infoDto = new StudentInfoDto();
        infoDto.setGradeId(47L);
        infoDto.setGradeName("八年级");
        infoDto.setOrgName("因时学校11");
        infoDto.setClassName("九年级一班11");
        infoDto.setName("俗称");
        infoDto.setSex("男");
        infoDto.setStudentNo("123");
        System.out.println(JsonUtil.objectToJson(infoDto));
    }
}
